package jobscheduling.algorithms.pso;


public class Evaluator 
{
	private InputData data;
	public Evaluator(InputData data)
	{
		this.data = data;
	}
	 
	int[] convertIntoSolution(Particle p)//int[] !!
	{
		int jobs = data.getJobs();
		int[] solution = new int[jobs];
		
		for(int i=0; i<jobs; i++)
		{
			for(int j=0; j<jobs; j++)
			{
				if(p.jobPositions[i][j]==1)
					solution[j] = i;
			}
		}
		return solution;
	}
	
	public int[] convertIntoSolution(int [][]jobPositions)//int[] !!
	{
		int jobs = jobPositions.length;
		int[] solution = new int[jobs];
		
		for(int i=0; i<jobs; i++)
		{
			for(int j=0; j<jobs; j++)
			{
				if(jobPositions[i][j]==1)
					solution[j] = i;
			}
		}
		return solution;
	}
	
	
	public int eval(Particle p)
	{
		return SolutionEvaluator.getEval(data, convertIntoSolution(p));
	}
	
	public int eval(int[][] jobPositions)
	{
		return SolutionEvaluator.getEval(data, convertIntoSolution(jobPositions));
	}
	
	public Boolean compare(Particle p1, Particle p2)
	{
		return eval(p1) < eval(p2);
	}
	
	public Boolean compare(int[][] jobPositions1, int[][] jobPositions2)
	{
		return eval(jobPositions1) < eval(jobPositions2);
	}
}
